using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace MyCityCab.Core
{
    /// <summary>
    /// Controller class for Journey
    /// </summary>
    [System.ComponentModel.DataObject]
    public partial class JourneyController
    {
        // Preload our schema..
        Journey thisSchemaLoad = new Journey();
        private string userName = string.Empty;
        protected string UserName
        {
            get
            {
				if (userName.Length == 0) 
				{
    				if (System.Web.HttpContext.Current != null)
    				{
						userName=System.Web.HttpContext.Current.User.Identity.Name;
					}

					else
					{
						userName=System.Threading.Thread.CurrentPrincipal.Identity.Name;
					}

				}

				return userName;
            }

        }

        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public JourneyCollection FetchAll()
        {
            JourneyCollection coll = new JourneyCollection();
            Query qry = new Query(Journey.Schema);
            coll.LoadAndCloseReader(qry.ExecuteReader());
            return coll;
        }

        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public JourneyCollection FetchByID(object Id)
        {
            JourneyCollection coll = new JourneyCollection().Where("Id", Id).Load();
            return coll;
        }

		
		[DataObjectMethod(DataObjectMethodType.Select, false)]
        public JourneyCollection FetchByQuery(Query qry)
        {
            JourneyCollection coll = new JourneyCollection();
            coll.LoadAndCloseReader(qry.ExecuteReader()); 
            return coll;
        }

        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public bool Delete(object Id)
        {
            return (Journey.Delete(Id) == 1);
        }

        [DataObjectMethod(DataObjectMethodType.Delete, false)]
        public bool Destroy(object Id)
        {
            return (Journey.Destroy(Id) == 1);
        }

        
        
    	
	    /// <summary>
	    /// Inserts a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Insert, true)]
	    public void Insert(int Id,int RouteId,decimal Fare,string CurrencyCode,int? WeatherStatusId,int? StreetStatusId,DateTime JourneyDate,int? TimeOfDayId,int? UserId,int? CarModelId,decimal Rate,string Story)
	    {
		    Journey item = new Journey();
		    
            item.Id = Id;
            
            item.RouteId = RouteId;
            
            item.Fare = Fare;
            
            item.CurrencyCode = CurrencyCode;
            
            item.WeatherStatusId = WeatherStatusId;
            
            item.StreetStatusId = StreetStatusId;
            
            item.JourneyDate = JourneyDate;
            
            item.TimeOfDayId = TimeOfDayId;
            
            item.UserId = UserId;
            
            item.CarModelId = CarModelId;
            
            item.Rate = Rate;
            
            item.Story = Story;
            
	    
		    item.Save(UserName);
	    }

    	
	    /// <summary>
	    /// Updates a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
	    public void Update(int Id,int RouteId,decimal Fare,string CurrencyCode,int? WeatherStatusId,int? StreetStatusId,DateTime JourneyDate,int? TimeOfDayId,int? UserId,int? CarModelId,decimal Rate,string Story)
	    {
		    Journey item = new Journey();
		    
				item.Id = Id;
				
				item.RouteId = RouteId;
				
				item.Fare = Fare;
				
				item.CurrencyCode = CurrencyCode;
				
				item.WeatherStatusId = WeatherStatusId;
				
				item.StreetStatusId = StreetStatusId;
				
				item.JourneyDate = JourneyDate;
				
				item.TimeOfDayId = TimeOfDayId;
				
				item.UserId = UserId;
				
				item.CarModelId = CarModelId;
				
				item.Rate = Rate;
				
				item.Story = Story;
				
		    item.MarkOld();
		    item.Save(UserName);
	    }

    }

}

